package com.travel.travel_springboot_web.mapper;

import com.travel.travel_springboot_web.entity.GoodsImage;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface GoodsImageMapper {
    @Insert("INSERT INTO goods_images (goods_id, image_url, sort, created_at) " +
            "VALUES (#{goodsId}, #{imageUrl}, #{sort}, NOW())")
    int insert(GoodsImage goodsImage);
    
    @Select("SELECT image_url FROM goods_images WHERE goods_id = #{goodsId} ORDER BY sort")
    List<String> findByGoodsId(Long goodsId);
    
    @Delete("DELETE FROM goods_images WHERE goods_id = 0")
    int deleteUnlinkedImages();
    
    @Update("UPDATE goods_images SET goods_id = #{goodsId} WHERE image_url = #{imageUrl}")
    int updateGoodsId(@Param("goodsId") Long goodsId, @Param("imageUrl") String imageUrl);
    
    @Delete("DELETE FROM goods_images WHERE goods_id = #{goodsId}")
    int deleteByGoodsId(Long goodsId);
} 